package com.joysuch.wwyt.mh.controller;


import com.joysuch.wwyt.core.common.ajax.ResultBean;
import com.joysuch.wwyt.mh.bean.MhMajorHazardTaskSearchBean;
import com.joysuch.wwyt.mh.bean.vo.MhMajorHazardTaskVO;
import com.joysuch.wwyt.mh.dto.MhMajorHazardTaskRecordDTO;
import com.joysuch.wwyt.mh.entity.MhMajorHazardTaskRecord;
import com.joysuch.wwyt.mh.service.MhMajorHazardTaskService;
import com.joysuch.wwyt.repeatsubmit.NoRepeatSubmit;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zqw
 * @since 2022-05-24
 */
@RestController
@RequestMapping("/mh/mh-major-hazard-task")
@Api(tags = "重大危险源任务")
public class MhMajorHazardTaskController {

    @Autowired
    private MhMajorHazardTaskService mhMajorHazardTaskService;


    @PostMapping("/pageTask")
    @ApiOperation("分页查看危险源任务")
    public ResultBean pageTask(@RequestBody MhMajorHazardTaskSearchBean searchBean) {
        return mhMajorHazardTaskService.pageTask(searchBean);
    }

    @GetMapping("/findByAssignId")
    @ApiOperation("查看危险源任务详情")
    public ResultBean findByAssignId(Long assignId) {
        MhMajorHazardTaskVO vo = mhMajorHazardTaskService.findById(assignId);
        return ResultBean.success(vo);
    }

    @GetMapping("/deleteByAssignId")
    @ApiOperation("删除危险源任务")
    @RequiresPermissions("mh:major-hazard-task:deleteByAssignId")
    public ResultBean deleteById(Long assignId) {
        mhMajorHazardTaskService.deleteByAssignId(assignId);
        return ResultBean.success("");
    }

    @PostMapping("/finishTask")
    @ApiOperation("履职")
    @NoRepeatSubmit(paramNames = "taskId")
    @RequiresPermissions("mh:major-hazard-task:finishTask")
    public ResultBean finishTask(@RequestBody MhMajorHazardTaskRecordDTO recordDto) {
        MhMajorHazardTaskRecord record = mhMajorHazardTaskService.finishTask(recordDto);
        return ResultBean.success(record);
    }

    @GetMapping("/get-week-range-on-month")
    @ApiOperation("获取当月每周的开始结束时间")
    public ResultBean getWeekRangeOnMonth(int year, int month) {
        return ResultBean.success(mhMajorHazardTaskService.getWeekRangeOnMonth(year, month));
    }

    @GetMapping("/doOverdueTasksSchedule")
    @ApiOperation("定时处理过期任务")
    public ResultBean doOverdueTasksSchedule() {
        mhMajorHazardTaskService.doOverdueTasksSchedule();
        return ResultBean.success("");
    }

}

